package middware

import (
	"strings"

	"carmanager/util"

	"github.com/gin-gonic/gin"
)

// 定义中间
func MiddleWare() gin.HandlerFunc {
	return func(c *gin.Context) {
		isVeriry := strings.Contains(c.Request.URL.Path, "/system/Login")
		isVeriry = isVeriry || strings.Contains(c.Request.URL.Path, "/system/Login")
		//放行登录和注册接口
		if !isVeriry && strings.EqualFold(c.GetHeader("Authorization"), "") {
			util.Error(c, int(util.ApiCode.AUTHFAILED), "请先登录")
			return
		}
		c.Next()
	}
}
